package cn.jy.boot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloController {

    @Autowired
    private AuthenticationManager authenticationManager;

    @RequestMapping("/hello")
    public String hello(Model model){

        model.addAttribute("msg","hello Spring security");
//
//        SecurityContext context = SecurityContextHolder.getContext();
//        Authentication authentication = context.getAuthentication();
//        System.out.println("authentication"+authentication);
//        System.out.println("权限"+authentication.getAuthorities());
//        System.out.println("认证"+authentication.getPrincipal());
//        new Thread(() -> {
//            SecurityContext context1 = SecurityContextHolder.getContext();
//            Authentication authentication1 = context1.getAuthentication();
//            System.out.println("子线程"+authentication1);
//            System.out.println("权限"+authentication1.getAuthorities());
//            System.out.println("认证"+authentication1.getPrincipal());
//        }).start();

        return "hello";
    }
}
